﻿using System.Threading;

namespace Loki.Utils
{
    /// <summary>
    /// Base class for loggable object.
    /// </summary>
    public class LoggableObject
    {
        #region Log
        /// <summary>
        /// Gets the logger name ; must be redefined in derived classes.
        /// </summary>
        protected virtual string LoggerName
        {
            get
            {
                if (_LoggerName == null)
                {
                    _LoggerName = this.GetType().FullName;
                }

                return _LoggerName;
            }
        }

        private string _LoggerName = null;

        private ILog _Log = null;

        /// <summary>
        /// Gets the logger.
        /// </summary>
        /// <value>The logger.</value>
        protected ILog Log
        {
            get
            {
                if (_Log == null)
                {
                    Interlocked.CompareExchange(ref _Log, LokiServices.Logger.GetLogger(LoggerName), null);
                }

                return _Log;
            }
        }
        #endregion
    }
}